<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/3/15
 * Time: 12:22
 */

namespace App\Http\Logics\MiniProgramAdmin;


use App\SystemNotifyContent;
use App\Http\Logics\BaseLogic;
use App\Http\Logics\CommonLogic;
class SystemNotifyContentLogic extends BaseLogic
{
    public static function updateSystemNotifyContent($data)
    {
        errorLog($data);
        // 将之前的删除
        SystemNotifyContent::where('system_notify_id', $data['system_notify_id'])->delete();

        $content = json_decode($data['content_str']);
        foreach ($content as $key => $item){
            $system_notify_content = new SystemNotifyContent();
            // 公众参数
            $system_notify_content->system_notify_id = $data['system_notify_id'];
            $system_notify_content->sort = $key;
            $response = CommonLogic::handleContent($system_notify_content, $item);
            if ($response->code){
                return self::response($response->code, $response->data);
            }
        }
        return self::response(self::SUCCESS);
    }
}